package com.hualan.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.CourseEvaluateMapper;
import com.hualan.sfzy.model.entity.CourseClassify;
import com.hualan.sfzy.model.entity.CourseEvaluate;
import com.hualan.sfzy.service.CourseEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CourseEvaluateServiceImpl implements CourseEvaluateService {
    @Autowired
    CourseEvaluateMapper courseEvaluateMapper;
    @Override
    public int add(CourseEvaluate entity) {
        return courseEvaluateMapper.insert(entity);
    }

    @Override
    public int edit(CourseEvaluate entity) {
        return courseEvaluateMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return courseEvaluateMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseEvaluateMapper.deleteBatch(ids);
    }

    @Override
    public List<CourseEvaluate> find() {

        return courseEvaluateMapper.select(new CourseEvaluate());
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CourseEvaluate entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<CourseEvaluate> list = courseEvaluateMapper.select(entity);
        PageInfo<CourseEvaluate> pageInfo = new PageInfo<>(list);
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put(CommonConstant.PAGE_LIST, list);    // 当前页数据列表
        resultMap.put(CommonConstant.TOTAL, pageInfo.getTotal());      // 总记录数
        resultMap.put(CommonConstant.PAGE_NUM, pageInfo.getPageNum()); // 当前页码
        resultMap.put(CommonConstant.PAGE_SIZE, pageInfo.getPageSize()); // 每页大小
        resultMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());  // 总页数

        return resultMap;
    }

    @Override
    public CourseEvaluate findById(Integer id) {
        return courseEvaluateMapper.selectById(id);
    }

    @Override
    public int findCourseEvaluateByCourseId(int courseid) {

        return courseEvaluateMapper.selectCountByCourseId(courseid);
    }
//根据课程id 还有用户id查询评价
    @Override
    public CourseEvaluate findCourseEvaluateByCU(int userid, int courseid) {
        return courseEvaluateMapper.selectByUCId(userid, courseid);
    }
}
